<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Foundation\Http\Middleware\TransformsRequest;

class ConvertEmptyStringsToDel extends TransformsRequest
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $this->clean($request);

        foreach ($request->all() as $key => $v) {
            if ($request->$key === null) {
                unset($request[$key]);
            }
        }
        return $next($request);
    }
}
